# encoding:utf-8

"""
@version: python2.7
@author : 'l00383533'
@file   : desktop.py.py
@time   : 2017/3/30 15:08
"""

import sys
import win32api
import win32con
import win32gui


def setWallpaper(path):
    """
    Change wallpaper on windows
    :param path: picture path
    :return:
    """
    key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
    win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
    win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "1")
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, path, 1 + 2)


if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print "No path found! Use: python changeWallpaper.py <Image path>"
        exit(1)
    path = sys.argv[1]
    setWallpaper(path)
